﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using AmiEmuLib.Configuration.EventBindingConfig;
using System.Xml;
using TomanuExtensions.Utils;

namespace AmiEmuLib.AmigaConfiguration.InputConfig
{
    /// <summary>
    /// Input events map configuration.
    /// </summary>
    public class Input : XmlBase
    {
        /// <summary>
        /// Keyboard events map.
        /// </summary>
        public EventsBinding KeyboardEventsBinding;

        /// <summary>
        /// CDTV events map.
        /// </summary>
        public EventsBinding CDTVFrontPanelAndPilotEventsBinding;

        /// <summary>
        /// Shortcuts.
        /// </summary>
        public EventsBinding ShortcutsEventsBinding;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_reader"></param>
        public Input(XmlReader a_reader)
            : base(a_reader)
        {
        }

        protected override void ReadXml(XmlReader a_reader)
        {
            a_reader.ReadStartElement(GetType().Name);

            KeyboardEventsBinding = AmigaConfig.ResolveBindings(new EventsBinding(a_reader, false));
            ShortcutsEventsBinding = AmigaConfig.ResolveBindings(new EventsBinding(a_reader, false));
            CDTVFrontPanelAndPilotEventsBinding = 
                AmigaConfig.ResolveBindings(new EventsBinding(a_reader, false));

            a_reader.ReadEndElement();
        }

        public override void WriteXml(XmlWriter a_writer)
        {
            a_writer.WriteStartElement(GetType().Name);

            KeyboardEventsBinding.WriteXml(a_writer);
            ShortcutsEventsBinding.WriteXml(a_writer);
            CDTVFrontPanelAndPilotEventsBinding.WriteXml(a_writer);

            a_writer.WriteEndElement();
        }
    }
}
